<template>
	<div id="scoreDetail">
		<div class="breadcrumb">
			<img src="../../../../static/img/appoinment_1.png" class="head_img">
			<span class="title" @click="cancel()">成绩管理</span>/ 详情
		</div>

		<div class="list">
			<el-form ref="scoreForm" :model="scoreForm" label-width="160px" :inline="true">
				<div class="list_head">
					<span class="head_name">成绩详情</span>
					<el-button class="cancel" type="primary" @click="cancel()">返回</el-button>
				</div>
				<div class="mytitle">基本信息</div>
				<el-form-item label="学号" prop="campusId" required>
					<el-input v-model="scoreForm.campusId" class="el-input" disabled></el-input>
				</el-form-item>
				<el-form-item label="姓名" required>
					<el-input v-model="scoreForm.name" class="el-input" disabled></el-input>
				</el-form-item>
				<br>
				<el-form-item label="性别" required>
					<el-input v-model="scoreForm.gender" class="el-input" disabled></el-input>
				</el-form-item>
				<el-form-item label="年级" required>
					<el-input v-model="scoreForm.grade" class="el-input" disabled></el-input>
				</el-form-item>
				<br>
				<el-form-item label="院系" required>
					<el-input v-model="scoreForm.college" class="el-input" disabled></el-input>
				</el-form-item>
				<el-form-item label="体测名称" required>
					<el-select v-model="scoreForm.testId" class="el-input" disabled>
						<el-option v-for='item in tests' :label='item.name' :value='item.physicalId' :key='item.physicalId'></el-option>
					</el-select>
				</el-form-item>
				<br>
				<div class="mytitle">体测成绩</div>
				<el-form-item label="身高" prop="height" required>
					<el-input v-model="scoreForm.height" class="el-input" disabled></el-input>厘米
				</el-form-item>
				<el-form-item label="体重" prop="weight" required>
					<el-input v-model="scoreForm.weight" class="el-input" disabled></el-input>千克
				</el-form-item>
				<br>
				<el-form-item label="肺活量" prop="feihuoliang" required>
					<el-input v-model="scoreForm.feihuoliang" class="el-input" disabled></el-input>毫升
				</el-form-item>
				<el-form-item label="50米跑" prop="shortRun" required>
					<el-input v-model="scoreForm.shortRun" class="el-input" disabled></el-input>秒
				</el-form-item>
				<br>
				<el-form-item label="坐位体前屈" prop="qianqu" required>
					<el-input v-model="scoreForm.qianqu" class="el-input" disabled></el-input>厘米
				</el-form-item>
				<el-form-item label="立定跳远" prop="tiaoyuan" required>
					<el-input v-model="scoreForm.tiaoyuan" class="el-input" disabled></el-input>厘米
				</el-form-item>
				<br>
				<el-form-item label="1000米/800米跑" prop="longRun_min" required>
					<el-input v-model.number="scoreForm.longRun_min" class="mytime" disabled></el-input>分
				</el-form-item>
				<el-form-item prop="longRun_sec" required>
					<el-input v-model.number="scoreForm.longRun_sec" class="mytime" disabled></el-input>秒
				</el-form-item>
				<el-form-item label="引体向上/仰卧起坐" prop="up" required>
					<el-input v-model="scoreForm.up" class="el-input" disabled></el-input>次
				</el-form-item>
				<br>
				<el-form-item label="附加分" prop="extra" required>
					<el-input v-model.number="scoreForm.extra" class="el-input" disabled></el-input>
				</el-form-item>
			</el-form>
		</div>

	</div>
</template>

<script>
	import { mapState, mapActions } from "vuex";

	export default {
		data() {
			return {
				tests: [],
				scoreForm: {
					campusId: "",
					name: "",
					gender: "",
					grade: "",
					college: "",
					testId: "",
					height: "",
					weight: "",
					feihuoliang: "",
					shoreRun: "",
					qianqu: "",
					up: "",
					longRun_min: "",
					longRun_sec: "",
					extra: ""
				}
			};
		},
		mounted() {
			this.getAllTest();
			this.getScoreDetail();
		},
		computed: mapState({ user: state => state.user }),
		methods: {
			//取消
			cancel() {
				let params = {
					physicalId: this.$util.getUrlParam("physicalId"),
					grade: this.$util.getUrlParam("grade"),
					college: this.$util.getUrlParam("college"),
					pageNum: this.$util.getUrlParam("pageNum"),
					keyword: this.$util.getUrlParam("keyword")
				};
				this.$util.refreshTo("/#/test_scoreManage", params);
			},
			//获取所有体测项
			getAllTest() {
				let url = this.$util.domain + "/physicaltest/common/testitemlist";

				this.$http({
					url,
					method: "POST"
				}).then(response => {
					if (response.data.error == 10000) {
						this.tests = response.data.data;
						this.scoreForm.testId = this.$util.getUrlParam("physicalId") * 1;
					}
				});
			},
			//转化时间
			timeFormat(time) {
				let int = parseInt(time / 60000);
				let float = Math.ceil((time / 1000 - 60 * int) * 10) / 10;
				let newTime = int + "'" + float + '"';

				return {
					time: newTime,
					minute: int,
					second: float
				};
			},
			//获取体测成绩详情
			getScoreDetail() {
				let url = this.$util.domain + "/physicaltest/physicaltestscoredetail";

				this.$http({
					url,
					method: "POST",
					body: JSON.stringify({
						physicalId: this.$util.getUrlParam("physicalId") * 1,
						uid: this.$util.getUrlParam("uid") * 1
					})
				}).then(response => {
					if (response.data.error == 10000) {
						let dataObj = response.data.data;
						let longRunScore = this.timeFormat(dataObj.run);

						this.scoreForm = {
							name: dataObj.name,
							campusId: dataObj.campusId,
							grade: dataObj.grade + "级",
							college: dataObj.department,
							gender: dataObj.gender == 1 ? "男" : "女",
							extra: this.$util.getUrlParam("extraPoint"),
							testId: this.$util.getUrlParam("physicalId") * 1,
							height: dataObj.height == -99999 ? "" : dataObj.height / 10,
							weight: dataObj.weight == -99999 ? "" : dataObj.weight / 1000,
							shortRun: dataObj.run50 == -99999 ? "" : dataObj.run50 / 1000,
							up: dataObj.upperAbdomen == -99999 ? "" : dataObj.upperAbdomen,
							longRun_min: dataObj.run == -99999 ? "" : longRunScore.minute,
							longRun_sec: dataObj.run == -99999 ? "" : longRunScore.second,
							qianqu: dataObj.sitAndReach == -99999 ? "" : dataObj.sitAndReach / 10,
							feihuoliang: dataObj.vitalCapacity == -99999 ? "" : dataObj.vitalCapacity,
							tiaoyuan: dataObj.standingLongJump == -99999 ? "" : dataObj.standingLongJump / 10
						};
					}
				});
			}
		}
	};
</script>

<style scoped>
	#scoreDetail {
		padding-top: 80px;
		height: calc(100% - 100px);
	}

	.title {
		color: #0398ff;
	}

	#scoreDetail .mytitle {
		color: #48576a;
	}

	#scoreDetail .el-input {
		display: inline-block;
		width: 250px;
	}

	#scoreDetail .el-form-item {
		color: #48576a;
	}

	#scoreDetail .mytime {
		width: 118px;
	}
</style>